import { usecollageGoodsListStore } from '@/stores/Detail-collage'
import { ref, type Ref } from 'vue'
import type { IGoods } from '@/types/type'
import { Toast } from 'vant'
import { useRouter } from 'vue-router'

export const useCart = (getCurrentGoods:Function) => {
    const cartStore = usecollageGoodsListStore()
    const goodsList = cartStore.detailCollageList
    // const goodsList: Ref<Array<IGoods>> = ref([]) // 商品类别列表
    //ref()返回ref对象的数据类型是Ref
    const list: Ref<Array<IGoods>> = ref([])
    // 加载数据状态，true表示加载中,false加载完成
    const loading: Ref<boolean> = ref(false)
    // 加载更新完成数据状态, 所有数据加载完成设置为true
    const finished: Ref<boolean> = ref(false)
    // 下拉刷新状态
    const refreshLoading: Ref<boolean> = ref(false)
    // 当前页号
    let currentNo: number = 1
   
    

    // 弹出付款
    const show = ref(false);
    const showPopup = (id:number) => {
        show.value = true;
        // 拿当前商品的id    
        getCurrentGoods(id)
    };
    // 弹出付款方式
    const show2 = ref(false);
    const showPopup2 = () => {
        show2.value = true;
        
    };

    // 付款成功
    const Router = useRouter()
    const show3 = ref(false);
    const confirmPayment = () => {
        show3.value = true;
        Toast.success('付款成功');
        Router.push('/home')
    };

    // 去首页
      const goHome = () => {
        
        Router.push('/home')
    };

    // 商品列表
    const getProductList = goodsList


    //刷新成功与否
    const refreshing: Ref<boolean> = ref(false)
    refreshing.value = false
    //下拉刷新
    const onRefresh = () => {
        refreshing.value = false
    }

    
    // 拼团状态保存

    return {
        goHome,cartStore, goodsList, list, loading, finished, refreshLoading, onRefresh, refreshing, show,show2,
        showPopup,showPopup2,show3,confirmPayment
    }
}